home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / systracker_src / src / st_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-28  |  7.1 KB  |  279 lines

  1.  
  2. /*
  3.  * [!BGN - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  4.  *
  5.  *******************************************************************
  6.  *
  7.  * Program   : SysTracker (Experimental resource tracking system)
  8.  * Version   : 0.1
  9.  * File      : Work:Source/!WIP/SysTracker/st_main.c
  10.  * Author    : Andrew Bell
  11.  * Copyright : Copyright © 1999-2000 Andrew Bell. All rights reserved.
  12.  * Created   : Wednesday 03-Nov-99 18:00:00
  13.  * Modified  : Monday 14-Feb-00 00:10:00
  14.  * Comment   : 
  15.  *
  16.  * (Generated with StampSource 1.5 by Andrew Bell)
  17.  *
  18.  *******************************************************************
  19.  *
  20.  * [!END - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  21.  *
  22.  */
  23.  
  24. /* Created: Wed/03/Nov/1999 */
  25.  
  26. #include "SysTracker_rev.h"
  27. #include "st_include.h"
  28. #include "st_protos.h"
  29. #include "st_strings.h"
  30.  
  31. /***************************************************************************/
  32. /* Data and defines */
  33. /***************************************************************************/
  34.  
  35. struct Process *SysTrackerProcess = NULL;
  36.  
  37. const UBYTE *VersTag = VERSTAG;
  38.  
  39. /* Usually command names and sometimes tasks/process names can have
  40.    paths prefixed onto them, the next BOOL tells SysTracker to strip
  41.    them else leave them alone. */
  42.  
  43. BOOL cfg_RemovePaths = TRUE;
  44.  
  45. /* This is a special BOOL that determines if SysTracker should do
  46.    things that would be considered illegal by the system. For example,
  47.    accessing the exec lists in ExecBase. Setting this to FALSE makes
  48.    SysTracker more accurate in some areas. */
  49.  
  50. BOOL cfg_BeSystemLegal = FALSE;
  51.  
  52. /* Set this to TRUE if the lister should update automatically, so the
  53.    user doesn't have to click the "Update" button.
  54.  
  55.    Note: There seems to be a bug that causes every entry in the list
  56.          to be cloned when the user flushes dead apps, when the
  57.          following is set to TRUE. */
  58.  
  59. BOOL cfg_AutoUpdate = FALSE; /* !!This has since been removed!! */
  60.  
  61. /* Use this BOOL to turn debugging on and off. */
  62.  
  63. BOOL cfg_DebugMode = FALSE;
  64.  
  65. /* This tells the ARTL handler to keep track of resources that have
  66.    been freed. Setting this to TRUE is useful sometimes because it
  67.    allows the user to see all of the resources that have been accessed
  68.    by an application, instead of the currently allocated resources.
  69.    
  70.    Setting this to TRUE eats up more memory and slows down SysTracker. It
  71.    also tends to make the "Update" button unresponsive since the ARTL
  72.    Handler is semaphore locking the ARTL list more frequently. */
  73.  
  74. BOOL cfg_TrackUnusedResources = FALSE;
  75.  
  76. /* If this is TRUE, SysTracker will show unused resources as well as
  77.    used resources. This flag only makes sense when the
  78.    cfg_TrackUnusedResources flags is also TRUE. */
  79.  
  80. BOOL cfg_ShowUnusedResources  = TRUE;
  81.  
  82. /***************************************************************************/
  83.  
  84. LPROTO LONG wbmain( void )
  85. {
  86.   /*********************************************************************
  87.    *
  88.    * wbmain()
  89.    *
  90.    * Workbench entry point.
  91.    *
  92.    *********************************************************************
  93.    *
  94.    */
  95.  
  96.   return main();
  97. }
  98.  
  99. LPROTO int main( void )
  100. {
  101.   /*********************************************************************
  102.    *
  103.    * main()
  104.    *
  105.    * Need I say more? :-)
  106.    *
  107.    *********************************************************************
  108.    *
  109.    */
  110.  
  111.   static int retcode = RETURN_FAIL; /* Keep static! */
  112.  
  113.   #define SYSTRACKER_PRIORITY 1
  114.  
  115.   SetTaskPri(FindTask(NULL), SYSTRACKER_PRIORITY);
  116.  
  117.   if (MEM_Init())
  118.   {   
  119.     if (R_GetTasksStackSize() >= STACKSIZE)
  120.     {
  121.       if (M_InitPrg())
  122.       {
  123.         M_DoPrg(); retcode = RETURN_OK;
  124.       }
  125.       M_EndPrg();
  126.     }
  127.     else
  128.     {
  129.       /* OK, the environment that launched us hasn't provided us with
  130.          enough stack space, so we'll swap in a new stack. We need at
  131.          least 32KB of stack space. */
  132.  
  133.       static UBYTE *StackVec = NULL;
  134.  
  135.       /* Note: We *MUST* keep this off the stack, because most (if
  136.          not all) compilers store automatic/local variables on the
  137.          stack. So if the StackSwapStruct ends up on the stack, we
  138.          will have a little predicament. :) */
  139.  
  140.       static struct StackSwapStruct SSS;
  141.  
  142.       /* It's important that we use MEMF_PUBLIC for the stack memory! */
  143.  
  144.       if (StackVec = AllocVec(STACKSIZE, MEMF_PUBLIC | MEMF_CLEAR))
  145.       {
  146.         /* If StackSwap() fails altogether on your compiler you need
  147.            to remove this code and call it from some custom assembly
  148.            startup code. btw, you can't call StackSwap() with stubs
  149.            since the first and second StackSwap() calls need to be
  150.            called on the same stack level (i.e. in parallel). */
  151.  
  152.         SSS.stk_Lower = StackVec;
  153.         SSS.stk_Upper = (ULONG) (StackVec + STACKSIZE);
  154.         SSS.stk_Pointer = (APTR) SSS.stk_Upper;
  155.         StackSwap(&SSS);
  156.  
  157.         if (M_InitPrg())
  158.         {
  159.           M_DoPrg(); retcode = RETURN_OK;
  160.         }
  161.         M_EndPrg();
  162.  
  163.         StackSwap(&SSS);
  164.         FreeVec(StackVec);
  165.       }
  166.       else M_PrgError(STR_Get(SID_CANT_GET_STACK_MEM), NULL);
  167.     }
  168.     MEM_Free();   
  169.   }
  170.   else M_PrgError(STR_Get(SID_CANT_GET_MEMORY_RESOURCES), NULL);
  171.  
  172.   Delay(20); /* Very small delay, just to make sure the child process
  173.                 has time to RTS back into DOS after it signalled us.
  174.                 This reduces any possible chance of us ripping our
  175.                 seglist from under the child process. */
  176.  
  177.   return retcode;
  178. }
  179.  
  180. GPROTO void DEBUG( void )
  181. {
  182.  /* I use this for manual breakpoints */
  183. }
  184.  
  185. LPROTO BOOL M_InitPrg( void )
  186. {
  187.   /*********************************************************************
  188.    *
  189.    * M_InitPrg()
  190.    *
  191.    * Initialize the program. 
  192.    *
  193.    *********************************************************************
  194.    *
  195.    */
  196.  
  197.   SysTrackerProcess = (struct Process *) FindTask(NULL);
  198.  
  199.   if (!(SysBase->AttnFlags & AFF_68020))
  200.   {
  201.     M_PrgError(STR_Get(SID_OLD_CPU), NULL);
  202.     return FALSE;
  203.   }
  204.  
  205.   if (SysBase->LibNode.lib_Version < 39)
  206.   {
  207.     M_PrgError(STR_Get(SID_OLD_OS), NULL);
  208.     return FALSE;
  209.   }
  210.  
  211.   if (!LIBS_Init()) return FALSE;
  212.   if (!GUI_Construct()) return FALSE;
  213.  
  214.   return TRUE;
  215. }
  216.  
  217. LPROTO void M_EndPrg( void )
  218. {
  219.   /*********************************************************************
  220.    *
  221.    * M_EndPrg()
  222.    *
  223.    * Free the resources allocated by M_EndPrg().
  224.    *
  225.    *********************************************************************
  226.    *
  227.    */
  228.  
  229.   GUI_Destruct();
  230.   LIBS_Free();
  231. }
  232.  
  233. LPROTO void M_DoPrg( void )
  234. {
  235.   /*********************************************************************
  236.    *
  237.    * M_DoPrg()
  238.    *
  239.    * The main program.
  240.    *
  241.    *********************************************************************
  242.    *
  243.    */
  244.  
  245.   if (ARTL_Init()) /* Launch the ARTL handler process */
  246.   {
  247.     for (;;)
  248.     {
  249.       GUI_Act_Window_Open(OID_MAIN_WINDOW, TRUE);   
  250.       GUI_EventHandler(); 
  251.       if (ARTL_Free()) break;
  252.     }
  253.   }
  254.   else
  255.   {
  256.     ARTL_Free();
  257.     M_PrgError(STR_Get(SID_CANT_INVOKE_HANDLER), NULL);
  258.   }
  259. }
  260.  
  261. GPROTO void M_PrgError( UBYTE *ErrStr, APTR ErrFmt )
  262. {
  263.   /*********************************************************************
  264.    *
  265.    * M_PrgError()
  266.    *
  267.    * Show an error requester.
  268.    *
  269.    *********************************************************************
  270.    *
  271.    */
  272.  
  273.   GUI_Popup(STR_Get(SID_ERROR), ErrStr, ErrFmt, STR_Get(SID_OK));
  274. }
  275.  
  276.  
  277.  
  278.  
  279.